// components/wegets/day-activity-cell/day-activity-cell.ts
import dayjs from "dayjs";
import {post} from "@utils/http"
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import { planStore } from "@store/plans";
import { getPlanBehavior } from "@mixin/plan";
Component({
  /**
   * 导入第三方计划状态库
   */
  behaviors: [storeBindingsBehavior,getPlanBehavior],
  storeBindings: {
    store: planStore, //使用 observable 函数创建的 observable 对象，常被叫做 store
    actions: ["setPlanList","setWeekStatusList"], //observable 对象中的 action
  },
  /**
   * 组件的属性列表
   */
  properties: {
    detail:{}
  },

  /**
   * 组件的初始数据
   */
  data: {
    time:"",
    endTime:""
  },
  attached:function(){
    const {start,end}=this.properties.detail
    this.setData({
      time:`${dayjs(start).format("HH:mm A")} - ${dayjs(end).format("HH:mm A")}`,
      endTime:dayjs(end).format("MM.DD截止")
    })
  },

  /**
   * 组件的方法列表
   */
  methods: {
    activityToplan:async function(e:any){
      const {id}=e.currentTarget.dataset
       await post(`/activity/plan?activityId=${id}`)
      wx.showToast({
        title:"加入计划成功"
      })
      this.setData({
        detail:{
          ...this.data.detail,
          isAddedToPlan:true
        }
      })
      this.getPlan()
    },
    getDetail(){
      wx.navigateTo({
        url:"/pages/activity/activity-detail/activity-detail?id="+this.data.detail.id
      })
    }
  }
})